<?php

/**
 * This is the model class for table "tb_news".
 *
 * The followings are the available columns in table 'tb_news':
 * @property string $news_id
 * @property string $news_title
 * @property string $news_detail
 * @property string $news_content
 * @property string $news_pic_path
 * @property string $created_by
 * @property string $created_date
 * @property string $updated_by
 * @property string $updated_date
 */
class News extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return News the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tb_news';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('news_title', 'required'),
			array('news_title, news_detail', 'length', 'max'=>255),
			array('news_pic_path', 'length', 'max'=>200),
			array('created_by, updated_by', 'length', 'max'=>20),
			array('news_content, created_date, updated_date', 'safe'),
            
            array('created_date','default',
            'value'=>new CDbExpression('NOW()'),
            'setOnEmpty'=>false,'on'=>'insert'),
            array('updated_date','default',
            'value'=>new CDbExpression('NOW()'),
            'setOnEmpty'=>false,'on'=>'insert'),
            array('updated_date','default',
            'value'=>new CDbExpression('NOW()'),
            'setOnEmpty'=>false,'on'=>'update'),
            
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('news_id, news_title, news_detail, news_content, news_pic_path, created_by, created_date, updated_by, updated_date', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'news_id' => 'News',
			'news_title' => 'News Title',
			'news_detail' => 'News Detail',
			'news_content' => 'News Content',
			'news_pic_path' => 'News Pic Path',
			'created_by' => 'Created By',
			'created_date' => 'Created Date',
			'updated_by' => 'Updated By',
			'updated_date' => 'Updated Date',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('news_id',$this->news_id,true);
		$criteria->compare('news_title',$this->news_title,true);
		$criteria->compare('news_detail',$this->news_detail,true);
		$criteria->compare('news_content',$this->news_content,true);
		$criteria->compare('news_pic_path',$this->news_pic_path,true);
		$criteria->compare('created_by',$this->created_by,true);
		$criteria->compare('created_date',$this->created_date,true);
		$criteria->compare('updated_by',$this->updated_by,true);
		$criteria->compare('updated_date',$this->updated_date,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}